package com.example.graduation.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.graduation.entity.Shop;
import com.example.graduation.form.*;
import com.example.graduation.service.ShopService;
import com.example.graduation.service.impl.ShopServiceImpl;
import com.example.graduation.util.R;
import com.example.graduation.vo.ShopInfoVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xyc
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Resource
    private ShopService shopService;

    @Resource
    private ShopServiceImpl shopServiceimpl;


    /**
     * @api {POST} /shop/selectShopById 根据商店id查询商店
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName selectShopById
     * @apiParam (请求体) {Number} shopId
     * @apiParam (请求体) {Number} status
     * @apiParam (请求体) {Number} type
     * @apiParam (请求体) {Number} goodsStatus
     * @apiParamExample 请求体示例
     * {"goodsStatus":4466,"shopId":8985,"type":1794,"status":6559}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectShopById")
    @ResponseBody
    public R selectShopById(@RequestBody SelectShopForm form) {
        ShopInfoVo shopInfoVo = shopService.selectShopById(form.getShopId(), form.getStatus(), form.getType(), form.getGoodsStatus());
        return R.ok("查询成功").put("shopInfoVo", shopInfoVo);
    }


    /**
     * @api {POST} /shop/selectShopInfo 查询商店的详细信息
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName selectShopInfo
     * @apiParam (请求体) {Number} shopId
     * @apiParam (请求体) {Number} status
     * @apiParamExample 请求体示例
     * {"shopId":445,"status":7564}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectShopInfo")
    @ResponseBody
    public R selectShopInfo(@RequestBody SelectShopInfoForm form) {
        Shop shop = shopService.selectShopInfo(form.getShopId());
        return R.ok("查询成功").put("shop", shop);
    }


    /**
     * @api {POST} /shop/selectShopByToken 查询本人商店信息
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName selectShopByToken
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=vb7eoAv
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectShopByToken")
    @ResponseBody
    public R selectShopByToken(@RequestHeader String token) {
        Shop shop = shopServiceimpl.selectShopByToken(token);
        return R.ok().put("shop", shop);
    }


    /**
     * @api {POST} /shop/findallshop 查询所有店铺
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName findallshop
     * @apiParam (请求体) {Number} page
     * @apiParam (请求体) {Number} size
     * @apiParamExample 请求体示例
     * {"size":2321,"page":7537}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findallshop")
    @ResponseBody
    public R findallshop(@RequestBody PageSizeForm form) {
        Page<Shop> page = shopServiceimpl.findallshop(form.getPage(), form.getSize());
        return R.ok().put("page", page);
    }


    /**
     * @api {POST} /shop/fingshopByType 根据类型查询商店
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName fingshopByType
     * @apiParam (请求体) {String} shoptype
     * @apiParamExample 请求体示例
     * {"shoptype":"V"}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/fingshopByType")
    @ResponseBody
    public R fingshopByType(@RequestBody TypeForm form) {
        List<Shop> shops = shopServiceimpl.fingshopByType(form.getShoptype());
        return R.ok().put("shops", shops);
    }


    /**
     * @api {POST} /shop/findShop 查询商店信息
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName findShop
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findShop")
    @ResponseBody
    public R findShop() {
        List<Shop> shops = shopServiceimpl.findShop();
        return R.ok().put("shops", shops);
    }


    /**
     * @api {POST} /shop/finishOrder 用户点击完成订单
     * @apiVersion 1.0.0
     * @apiGroup ShopController
     * @apiName finishOrder
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=4OswtpiOYT
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":2509}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/finishOrder")
    @ResponseBody
    public R finishOrder(@RequestHeader String token, @RequestBody LongId id) {
        shopServiceimpl.finishOrder(token, id.getId());
        return R.ok();
    }

}

